Skip to content

test(rivetkit): cover failed preflight disconnect handling#4973

Merged
NathanFlurry merged 1 commit intomainfrom
conn-preflight/no-disconnect-on-failed-preflight
May 5, 2026
Merged

test(rivetkit): cover failed preflight disconnect handling#4973
NathanFlurry merged 1 commit intomainfrom
conn-preflight/no-disconnect-on-failed-preflight

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented May 5, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 5, 2026

Code Review: test(rivetkit): cover failed preflight disconnect handling

Overview

This PR adds test coverage for the scenario where a connection transport closes (or the preflight is rejected) during the preflight phase, verifying that onDisconnect is never called for connections that never fully established. Coverage spans two layers:

  1. Rust unit test (rivetkit-core/tests/connection.rs): verifies that no ConnectionClosed event is emitted when a transport is closed mid-preflight.
  2. TypeScript driver test (conn-preflight-disconnect.test.ts): verifies from the client side that onDisconnect callbacks aren't fired and rejected connections don't appear in visibleLabels.

Issues

Narrow test matrix (most important)

The new TS driver test is the only test in the suite that restricts runtimes:

{
    encodings: ["bare"],
    runtimes: ["wasm"],       // only test in the suite to restrict this
    sqliteBackends: ["remote"],
}

Every other driver test (e.g. conn-error-serialization.test.ts) passes no runtime restriction and runs across all configured runtimes. If the preflight disconnect behavior is expected to work correctly in both native and wasm runtimes — and based on the Rust-layer test it should be — the matrix should include native as well. If there's a known reason this only applies to wasm (e.g. the bug path only exists there), a comment would help future readers understand why.

Incomplete snapshot assertions

The test asserts that disconnectSnapshots is empty and visibleLabels contains only "primary", but doesn't verify:

  • connectSnapshots has exactly one entry (confirming onConnect fired only for the primary connection, not for the rejected ones).
  • beforeStarted / createStarted counts to confirm the preflight hooks did run (but rejected).

These would lock in the full contract of the behavior being tested and prevent regressions in counter accounting.


Minor

Rust test: 20 ms hard-coded timeout

if let Ok(Some(ActorEvent::ConnectionClosed { conn })) =
    tokio::time::timeout(Duration::from_millis(20), events_rx.recv()).await

Testing for the absence of an event necessarily requires a time bound, so some wall-clock wait is unavoidable here. 20 ms is reasonable in practice, but could be marginal on very slow CI workers. Matches the pattern already established in the file for other absence checks, so acceptable as-is.

Rust test: unchecked reply.send return

reply.send(Err(anyhow::anyhow!("reject after transport close")));

The return value is silently discarded. The existing tests in this file follow the same convention (lines 94, 107, 144), so it's consistent — worth noting as a pattern to clean up if the oneshot sender type is ever changed.


Positive notes

  • The Rust test cleanly isolates the core invariant: transport close during preflight must never produce a ConnectionClosed event.
  • The fixture changes (rejectBefore / rejectCreate) are optional and backward-compatible with no impact on existing tests.
  • Using crypto.randomUUID() in the actor key ensures test isolation across runs.
  • The test name ("should not call onDisconnect when preflight fails") clearly states the invariant being guarded.

@NathanFlurry NathanFlurry force-pushed the conn-preflight/no-disconnect-on-failed-preflight branch from e987ebe to 342f41d Compare May 5, 2026 13:09
@NathanFlurry NathanFlurry marked this pull request as ready for review May 5, 2026 13:20
Base automatically changed from conn-preflight/hide-pending-conns to main May 5, 2026 14:58
@NathanFlurry NathanFlurry merged commit 342f41d into main May 5, 2026
7 of 13 checks passed
@NathanFlurry NathanFlurry deleted the conn-preflight/no-disconnect-on-failed-preflight branch May 5, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants